Data Science · Year 3 14 min read

Experiments & Causal Inference: Why a Coin Flip Beats a Clever Model

Data tells you what goes with what. Whether pulling a lever changes anything is a different question, and answering it takes a design, not more data.
The Default Library · What Each Major Knows · 36/34

For decades, doctors read the same pattern in large observational studies: women who took hormone therapy after menopause had fewer heart attacks. It was a big, careful body of research, and the advice followed it. Then the Women's Health Initiative did something simpler. It assigned thousands of women, by lot, to hormones or a placebo. The trial's combined-hormone arm was stopped early in 2002 because the treated women had more breast cancer and more cardiovascular events, not fewer (Rossouw and colleagues, JAMA, 2002). Researchers still discuss why the earlier studies pointed the other way. One often-cited explanation is that women who chose hormones were healthier and better off to begin with, in ways that adjusting for recorded factors did not fully remove.

That is the central worry of this subject. A pattern in data is a fact about the data. A cause is a claim about what would happen if you changed something, and no table of numbers contains that on its own. A graduate of a causal-inference course keeps a habit: before looking at an estimate, ask what would have happened to these same people without the treatment, and what in the design makes the comparison fair.

The tools are old and new. Ronald Fisher built the logic of randomised experiments at the Rothamsted agricultural station in the 1920s and wrote it up in The Design of Experiments (1935). The formal language of "what would have happened" came from Jerzy Neyman (1923) and Donald Rubin (1974), and Judea Pearl's diagrams (from the 1980s, in Causality, 2000) turned it into something you can draw. Today the same ideas run every A/B test at every large web company.

The course in one box
Who takes it
Data science and statistics majors, usually in year 3 after regression; also economics, epidemiology and public-health students, who often meet it as "causal inference" or inside econometrics. Programmes differ in emphasis: statistics departments favour potential outcomes and randomisation, computer science favours Pearl's graphs, and economics favours natural experiments. Technology companies teach the experimentation side in-house.
What it is for
Answering "what would change if we did this?", and knowing when the data in hand can and cannot answer it.
Comes after
Regression & Statistical Modeling (36/33).
Leads to
No later subject in this major lists it as a prerequisite. It underlies the testing of a model's effects in Data Ethics, Privacy & Fairness (36/37), and connects to Research Methods in Psychology (35/19) and Econometrics (34/44).
What this piece gives you
You will not be able to design a clinical trial or run an experimentation platform. You will see why a coin flip beats a clever model, how to draw the story before touching a regression, and why an A/B test can mislead. For the econometric toolkit (difference-in-differences, instruments, cutoffs, and the minimum-wage study), read Econometrics (34/44); this piece does not repeat it. A first read on spotting the trap is the Simpson's paradox section of Probability & Statistics (34/05).

Aggregates can reverse: Simpson's paradox

In the fall of 1973, the University of California, Berkeley received 8,442 graduate applications from men and 4,321 from women. About 44% of the men and 35% of the women were admitted. It looks like proof of bias against women, and a lawsuit was threatened. Peter Bickel, Eugene Hammel and J. W. O'Connell looked inside (Science, 1975). Admissions are decided department by department, so they went there.

Take the six largest departments (anonymised as A to F in the paper). Together, 45% of the men and 30% of the women were admitted. But in four of the six departments, a higher share of women than men were admitted. The reason is where people applied. Women applied in large numbers to departments that rejected most applicants (in C to F, admission rates of 35% or less in the table below); men applied heavily to A and B, which admitted nearly two thirds. A fact about the whole reverses inside every part: Simpson's paradox.

Interactive · Berkeley, 1973 (real data, six largest departments)

Source: Bickel, Hammel and O'Connell, Science 187 (1975); the figures are those of the six largest departments as commonly reproduced (the R dataset UCBAdmissions). Departments were anonymised in the paper.

Without JavaScript: pooled, 44.5% of 2,691 men and 30.4% of 1,835 women were admitted. In departments A, B, D and F women's rates were higher; in C and E men's were. If women had applied in the men's proportions, the same department rates would give 51.6%.

The tempting lesson, "always look at the subgroups", is wrong. The right lesson is that the data cannot tell you which view answers the question. If the question is "does a department discriminate in its decisions?", the department-level numbers are the right ones. If the question is "why do far fewer women end up in the programmes that admit most?", the pooled view and the earlier steps (who is encouraged to apply where) become the story. Which table to trust depends on the causal arrows, and the next sections give you a way to draw them. Bickel and colleagues concluded that the pooled gap came from where people applied, and that the department-level data showed, if anything, a small bias favouring women.

The missing counterfactual, and why a coin fixes it

The language that makes this precise is simple. Every person has two potential outcomes: how they would do if treated, and how they would do if not. Call them Y(1) and Y(0). The effect on that person is the difference. And we can never see both, because each person is treated or not: this is "the fundamental problem of causal inference" (Paul Holland's phrase, 1986). Every causal estimate fills in the missing half with a stand-in group, and the whole subject is about when the stand-in is fair.

average effect = average of Y(1) − Y(0) over everyonewhat we want. What we can compute is: average of Y among the treated − average of Y among the untreated

The two agree when who gets treated has nothing to do with how people would have done anyway. They disagree when it does: if sicker people seek out the treatment, the treated group does worse on average, and the treatment looks harmful even when it helps each person. Below are 200 invented patients. The treatment truly raises everyone's recovery score by 6. Turn up how strongly the sicker patients choose treatment, then press "Peek" to see the column nobody gets to see in real life.

Interactive · Who chose the treatment? (invented patients)
How strongly sicker patients seek treatment0.5

Invented data. Recovery without treatment is 70 minus 30 times severity (severity 0 to 1) plus noise; treatment adds exactly 6 for everyone.

Without JavaScript: when sicker patients are much more likely to choose treatment, the treated group's average recovery is about 4 points below the untreated group's, although the treatment adds 6.

Randomisation breaks the link. If a coin decides who is treated, the two groups are alike in everything: severity, motivation, genes, luck, and things nobody measured. On average the treated-minus-untreated difference then equals the true average effect. "On average" matters: one experiment can still be off by chance, so repeat it and watch.

Interactive · The same study, 300 times
How strongly sicker patients seek treatment1
patients choose   coin flip assigns
estimated effect, from -6 to 14 (true effect: 6)
Press the button.

Without JavaScript: in 300 simulated studies at full selection, patient-chosen treatment gave an average estimate of -4.0 (5th to 95th percentile -5.5 to -2.3); coin-flip assignment gave 6.1 (3.7 to 8.2). The truth is 6.

Notice two things. The coin's estimates scatter around the truth, with the scatter set by sample size. The self-selected estimates scatter around the wrong number, and a bigger sample would only make them confidently wrong.

Draw the arrows first: confounders, mediators and colliders

Randomisation is the gold standard but often impossible or unethical: you cannot assign people to smoke. Then you rely on assumptions about how the data came to be, and Pearl's causal diagrams (directed acyclic graphs) make those assumptions visible. Each arrow says "this directly affects that". Three shapes cover most of what goes wrong:

The surprising part is the last: adding a control variable can make an estimate worse. The rule is not "adjust for everything you have". It is "adjust for what the diagram says you should". Try each story below on simulated data in which the true answer is known.

Interactive · Adjust, or not? (simulated data, 4,000 people)

Each story is simulated with known arrow strengths and the slope of Y on X is fitted by least squares, with or without the other variable. Names and numbers are illustrative.

Without JavaScript: in the heat story, the raw slope is about 0.63 and falls to about 0 after adjusting. In the fame story it is about 0 raw and about -0.8 after adjusting. In the exercise story the raw slope of -0.60 is the total effect, and adjusting leaves only the direct part, -0.2.

Experiments in practice: noise, power and peeking

Most experiments today are A/B tests. Half the visitors see version A, half see B, a coin decides, and you compare a metric such as the share who buy. The logic is exactly that of the previous section, so the worry is noise rather than bias. Suppose 10% of visitors buy, and the change really adds one percentage point. With 5,000 visitors per arm, the difference you observe wobbles by about 0.6 points from chance alone, so a one-point effect is only 1.7 wobbles tall. A standard rule of thumb (Lehr's formula, in van Belle's Statistical Rules of Thumb) says you need roughly this many per arm for 80% power at the 5% level:

n per arm ≈ 16 × p(1 − p) ÷ (effect)²for p = 0.10 and an effect of 0.01, that is 16 × 0.09 ÷ 0.0001 = 14,400 per arm

Power is the chance that a real effect is detected. Underpowered tests miss real effects, and, because only the lucky big estimates reach significance, the winners they do find exaggerate the effect. The second trap is peeking. If you look at the running result every day and stop the first time p dips under 0.05, you are giving chance many tries. With ten looks, a test with no true effect declares a winner about 19% of the time (in the run below), not 5%. Sequential tests exist that allow peeking honestly, and are what large experimentation platforms use. A third trap is the number of metrics: with 20 independent metrics and no real effect, the chance that at least one shows p below 0.05 is 1 − 0.9520, about 64%.

Interactive · How often does a test "win"?
True lift in conversion (percentage points)0
Baseline conversion is 10%. Press Run.

Each run draws every visitor at random and tests the difference in proportions (two-sided z-test). With only 400 runs the percentages carry a couple of points of noise.

Without JavaScript: with a true lift of 0, 400 experiments of 1,000 visitors per arm give a "winner" about 4% of the time if you look once, and about 19% if you peek ten times. With 5,000 per arm and a true one-point lift, about 37% win with a single look.

Interference: when your treatment changes the control

Everything above quietly assumed that one person's treatment does not affect another's outcome. Rubin called this the "stable unit treatment value assumption". It fails whenever units compete or talk. Vaccinate half a town and the unvaccinated are protected too. Give half the sellers on a marketplace a discount and they take sales from the other half. Show half of a social network's users a new feed and their friends in the control group are affected.

The marketplace case is the clearest. Suppose 100 sellers share a fixed pool of 1,000 buyers. In a test, a randomly chosen share gets a discount that makes them more attractive. The test compares treated sellers with control sellers and reports a big lift. But much of it was taken from the controls. If everyone got the discount, nothing would change in a fixed market. Engineers meet this in two-sided platforms, ride-hailing and ad auctions, and respond with experiments randomised by whole cities, regions or time blocks, which cost power but keep the arms from touching.

Interactive · A discount test on a marketplace (illustrative model)
Share of sellers in the test group50%
How much more attractive the discount makes a seller1.5×
Extra buyers drawn in if everyone discounts0%

Model: 100 sellers, about 1,000 buyers; each buyer picks a seller with probability proportional to attractiveness (1 for a normal seller). The extra-buyers slider is an assumption about how much total demand grows with the share discounting. Sales are per seller per day.

Without JavaScript: with half the sellers discounted at 1.5 times as attractive and no extra demand, treated sellers sell 12 a day and control sellers 8. The test reports +50%. Giving everyone the discount changes nothing, so the true roll-out effect is 0%.

When you cannot randomise: adjust for what you measured, fear what you did not

With observational data, the standard move is to compare like with like on everything you recorded: split people into groups with similar severity (strata), match them, or model the chance of treatment from their characteristics (a propensity score, Rosenbaum and Rubin, 1983). If every factor that drives both treatment and outcome was measured, this works. The fatal catch is that you can never check that "if". The question to ask of every observational claim is: what unmeasured thing might have pushed people into the treatment and changed their outcome? Analysts now quantify how strong such a hidden factor would have to be to erase a result, with tools such as the E-value (VanderWeele and Ding, 2017).

Where a rule or an accident acts like a coin flip, you can do better than adjustment: a policy that hit one state but not its neighbour (difference-in-differences), a lottery that nudged people (instrumental variables), a cutoff that put near-identical people on either side (regression discontinuity), or a weighted blend of untreated places built to match the treated one (synthetic control, Abadie and colleagues). The 2021 economics Nobel prize went to David Card, and to Joshua Angrist and Guido Imbens, for this credibility revolution; Econometrics (34/44) works through three of them. Try the first idea here, and then the limit.

Interactive · Adjust for severity, but what about the hidden factor? (simulated)
Strength of an unmeasured factor (frailty)0

4,000 simulated patients. Severity is recorded; frailty is not, and it affects both who gets treated and how they fare. The true effect of treatment is +5. "Adjusted" compares treated and untreated within five severity bands and averages.

Without JavaScript: with no hidden factor, the raw difference is about -1.1 (the treatment looks harmful), and adjusting for severity gives about 4.7 against a truth of 5. With a hidden factor of strength 5, adjusting gives about -2.8.

What a graduate just sees

Where it shows up next

If you want to go deeper

The takeaway

Causal questions are about what would have happened otherwise, and only a fair stand-in for that answers them. A coin flip is the most reliable stand-in; failing that, draw the story, adjust only for what the diagram says, and say out loud what you could not measure.

Try this: take any "X is linked to Y" headline this week and write down one confounder, one possible reversal of direction, and what a randomised version of the study would look like. If you cannot imagine the experiment, you have found why it is hard.

Sources & Further Reading

Sources. Rossouw et al., JAMA 288 (2002), Writing Group for the Women's Health Initiative; Fisher, The Design of Experiments (1935); Neyman 1923 (translated in Statistical Science 1990); Rubin, Journal of Educational Psychology 1974 and "Randomization analysis of experimental data," JASA 1980; Holland, "Statistics and causal inference," JASA 1986; Pearl, Causality (2000); Berkson, Biometrics Bulletin 1946; Bickel, Hammel and O'Connell, "Sex bias in graduate admissions: data from Berkeley," Science 187 (1975), 398–404 (department-level counts for A to F as reproduced in the R dataset UCBAdmissions and in Wikipedia, "Simpson's paradox"); Rosenbaum and Rubin, Biometrika 1983; VanderWeele and Ding, Annals of Internal Medicine 2017; Abadie, Diamond and Hainmueller, JASA 2010; van Belle, Statistical Rules of Thumb (2nd ed. 2008); Nobel Prize in Economic Sciences 2019 (Banerjee, Duflo, Kremer) and 2021 (Card; Angrist and Imbens). All simulations, percentages and rules of thumb in the text were computed in node. Patients, sellers and visitors are invented.